﻿@model Himall.Model.MemberGrade
@{
    ViewBag.Title = "积分管理";
}
<script src="~/Scripts/jquery.placeholder.min.js"></script>
<script src="~/Scripts/bootstrap.autocomplete.js"></script>
<div class="container">
    <ul class="nav nav-tabs-custom clearfix">
        <strong>会员</strong>
        <li><a href="./Search">积分查询</a></li>
        <li class="active">@Html.ActionLink("积分管理", "Management", new { area = "admin" })</li>
    </ul>
    <form class="form-horizontal" id="v-form" method="post">
        <div class="form-group">
            <label for="" class="col-sm-2 control-label">会员帐号：</label>
            <div class="col-sm-8">
                <input class="form-control input-ssm" type="text" id="userName" name="userName" autocomplete="off">
            </div>
            <input type="hidden" name="userId" id="userId" />
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label">操作：</label>
            <div class="col-sm-8">
                <select id="Operation" name="Operation">
                    <option value="add">增加</option>
                    <option value="sub">减少</option>
                </select>
                <input class="form-control input-sm input-half" id="Integral" name="Integral" type="text" value="">
            </div>
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label">备注(选填)：</label>
            <div class="col-sm-8">
                <textarea class="form-control input-sm input-half" id="Remark" name="Remark" rows="5"></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="submit" class="btn btn-primary" value="保 存" />
            </div>
        </div>
    </form>
</div>
<script src="~/Scripts/v.js"></script>
<script>
    $(function () {
        AutoComplete();
    })
    function AutoComplete() {
        //autocomplete
        $('#userName').autocomplete({
            source: function (query, process) {
                var matchCount = this.options.items;//返回结果集最大数量
                $.post("./getMembers", { "keyWords": $('#userName').val() }, function (respData) {
                    return process(respData);
                });
            },
            formatItem: function (item) {
                return item.value;
            },
            setValue: function (item) {
                return { 'data-value': item.value, 'real-value': item.key };
            }
        });
    }

    var a = v({
        form: 'v-form',// 表单id 必须
        beforeSubmit: function () {
            var id = $("#userName").attr("real-value"); $("#userId").val(id);
            loadingobj = showLoading();
        },// 表单提交之前的回调 不是必须
        afterSubmit: function (data) {
            loadingobj.close();
            if (data.success) {
                // a.reset();                
                $.dialog.succeedTips(data.msg, function () {
                    window.location.href = "./Search";
                });
                
            } else {
                $.dialog.errorTips(data.msg);
            }
        },// 表单提交之后的回调 不是必须
        ajaxSubmit: true// 是否ajax提交 如果没有这个参数那么就是默认提交方式 如果没有特殊情况建议默认提交方式
    });
    a.add(
    {
        target: "userName",
        ruleType: "required",
        error: '会员名必填填写!'
    },
    {
        target: "Integral",
        ruleType: "required&&uint",
        tips: '该信息为必填项，请输入积分数!',
        error: '积分数为正整数且必填填写!'
    }
    );
</script>